package kr.ac.mju.mdc.mjuapp.information;

import java.util.ArrayList;

import kr.ac.mju.mdc.mjuapp.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class DeveloperHistoryListViewActivity extends Activity {

	ArrayList<DeveloperHistory> developerHistoryList;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	 
	    // TODO Auto-generated method stub
	    setContentView(R.layout.information_dev_history_list_layout);
	    developerHistoryList = new ArrayList<DeveloperHistory>();
	    
	    String[] periods = this.getResources().getStringArray(R.array.dev_history_period);
	    String[] developers = this.getResources().getStringArray(R.array.dev_history_developers);
	    
	    DeveloperHistory developerHistory;
	    
	    for (int i = 0; i < periods.length; i++) {
	    	developerHistory = new DeveloperHistory();
	    	developerHistory.setPeriod(periods[i].toString());
	    	developerHistory.setDeleloper(developers[i].toString());
	    	developerHistoryList.add(developerHistory);
	    }
	    
	    DeveloperHistoryAdapter dAdapter = new DeveloperHistoryAdapter(this, R.layout.information_dev_history_list_row_layout, developerHistoryList);
	    ListView lv = (ListView)findViewById(R.id.dev_history_listview);
	    lv.setAdapter(dAdapter);
	}
}

class DeveloperHistory {
	private String period;
	private String developers;
	
	public String getPeriod() {
		return period;
	}
	
	public void setPeriod(String period) {
		this.period = period;
	}
	
	public String getDevelopers() {
		return developers;
	}
	
	public void setDeleloper(String developers) {
		this.developers = developers;
	}
}

//어댑터 클래스
class DeveloperHistoryAdapter extends BaseAdapter {
	Context context;
	LayoutInflater Inflater;
	ArrayList<DeveloperHistory> developerHistoryList;
	int layout;

	public DeveloperHistoryAdapter(Context context, int layout, ArrayList<DeveloperHistory> list) {
		this.context = context;
		Inflater = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
		developerHistoryList = list;
		this.layout = layout;
	}

	public int getCount() {
		return developerHistoryList.size();
	}

	public String getItem(int position) {
		return developerHistoryList.get(position).getPeriod();
	}

	public long getItemId(int position) {
		return position;
	}

	// 각 항목의 뷰 생성
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = Inflater.inflate(layout, parent, false);
		}
		
		TextView peroid = (TextView)convertView.findViewById(R.id.dev_history_list_row_period);
		peroid.setText(developerHistoryList.get(position).getPeriod());
		
		TextView developer = (TextView)convertView.findViewById(R.id.dev_history_list_row_developer);
		developer.setText(developerHistoryList.get(position).getDevelopers());

		return convertView;
	}
}
/* end of file */